home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
tarsrc Folder
/
dialog.c
< prev
next >
Wrap
Text File
|
1993-11-28
|
15KB
|
724 lines
/*
* Macintosh Tar
*
* The routines in this file deal with the dialogs presented to the user.
*
* Written by Craig Ruff.
*
* Note that the dialog dealing with directory selection is in dir.c.
*/
#include "tar.h"
#include <Disks.h>
#include <Resources.h>
#include <SegLoad.h>
/*
* Dialog definitions
*/
#define aboutID 128 /* The "About ..." dialog */
#define okItem 1
#define blockID 129 /* The block size dialog */
#define sizeItem 3
#define typeID 131 /* Creator/Type dialog */
#define creatorItem 3
#define typeItem 4
#define saveItem 7
#define floppyID 132 /* Insert floppy dialog */
#define ejectItem 3
#define tapeID 133 /* Tape options dialog */
#define scsiIDItem 3
#define minTOItem 4
#define motionTOItem 5
#define rewindTOItem 6
#define densityItem 7
#define bufModeItem 8
#define speedItem 9
#define variableItem 10
#define modeSelectItem 11
/*
* Alert Definitions
*/
#define badBlockID 129 /* Block size incorrect alert */
#define osErrID 130 /* Generic OS Error alert */
#define pgmErrID 131 /* Program logic error alert */
#define versionID 132 /* Must run under 6.0.5 or later alert */
#define askipID 133 /* Skipping archive file note */
#define stkErrID 134 /* Stack error alert */
#define dfID 135 /* Disk full alert */
#define hfsID 136 /* Can only handle HFS volumes */
#define badTapeID 137 /* Bad SCSI Tape ID alert */
#define stopGoID 138 /* Generic Retry/Quit alert */
#define genericID 139 /* Generic alert */
/*
* AboutFilter - manage the "About ..." dialog
*
* Returns when the mouse or a key is pressed anywhere.
*/
pascal Boolean
AboutFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
#pragma unused(theDialog)
switch (theEvent->what) {
case keyDown:
case mouseDown:
*itemHit = 1;
return(true);
break;
default:
return(false);
break;
}
}
/*
* DoAboutBox - put the "About ..." dialog on the screen
*/
void
DoAboutBox(void)
{
short itemHit, itemType;
WindowPtr myWindow;
GrafPtr thePort;
PenState pn;
Rect okBox;
Handle okHdl;
GetPort(&thePort);
myWindow = GetNewDialog(aboutID, nil, (WindowPtr) -1);
GetDItem(myWindow, okItem, &itemType, &okHdl, &okBox);
SetPort(myWindow);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(AboutFilter, &itemHit);
} while (itemHit != 1);
DisposDialog(myWindow);
SetPort(thePort);
}
/*
* ValidBlockSize - checks the user entered blocksize for validity.
*
* Returns true if ok, false if bad.
*/
Boolean
ValidBlockSize(theDialog)
DialogPtr theDialog;
{
long n;
short type;
Handle hdl;
Rect box;
char text[256];
GetDItem(theDialog, sizeItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
/*
* These limits are somewhat arbitrary.
*/
if ((n < 1) || (n > 256)) {
NoteAlert(badBlockID, nil);
SelIText(theDialog, sizeItem, 0, 32767);
return(false);
}
pref.blocking = (int) n;
pref.blockSize = pref.blocking * RECORDSIZE;
return(true);
}
Rect okBox; /* ok Box location (gotten once for speed) */
ControlHandle okHdl; /* ok Box handle */
/*
* BlockFilter - manage user events during the block size dialog
*
* Allows numeric entry and editing, validates size.
* Returns true if the dialog should exit, false to continue.
*/
pascal Boolean
BlockFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
long t;
Point lpt;
GrafPtr savedPort;
switch (theEvent->what) {
case keyDown:
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
goto validate;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case TAB: case BS:
break;
default:
SysBeep(5);
theEvent->what = nullEvent;
break;
}
break;
case mouseDown:
lpt = theEvent->where;
GetPort(&savedPort);
SetPort((GrafPtr) theDialog);
GlobalToLocal(&lpt);
SetPort(savedPort);
if (PtInRect(lpt, &okBox)) {
validate: if (ValidBlockSize(theDialog)) {
*itemHit = ok;
HiliteControl(okHdl, 1);
Delay(8L, &t);
HiliteControl(okHdl, 0);
return(true);
} else
theEvent->what = nullEvent;
}
break;
}
return(false);
}
/*
* ValidTapeID - checks the user entered tape id for validity.
*
* Returns true if ok, false if bad.
*/
Boolean
ValidTapeID(theDialog)
DialogPtr theDialog;
{
long n;
short type;
Handle hdl;
Rect box;
char text[256];
GetDItem(theDialog, scsiIDItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
/*
* Mac is always ID 7
*/
if ((n < 0) || (n > 6)) {
NoteAlert(badTapeID, nil);
SelIText(theDialog, scsiIDItem, 0, 32767);
return(false);
}
pref.tapeVars.unit = (int) n;
return(true);
}
Rect variableBox; /* force variable Ctl location (gotten once for speed) */
ControlHandle variableHdl; /* force variable Ctl handle */
Rect modeBox; /* force mode select Ctl location (gotten once for speed) */
ControlHandle modeHdl; /* force mode select Ctl handle */
/*
* TapeFilter - manage user events during the tape id dialog
*
* Allows numeric entry and editing, validates id.
* Returns true if the dialog should exit, false to continue.
*/
pascal Boolean
TapeFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
long t;
Point lpt;
GrafPtr savedPort;
switch (theEvent->what) {
case keyDown:
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
goto validate;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case TAB: case BS:
break;
default:
SysBeep(5);
theEvent->what = nullEvent;
break;
}
break;
case mouseDown:
lpt = theEvent->where;
GetPort(&savedPort);
SetPort((GrafPtr) theDialog);
GlobalToLocal(&lpt);
SetPort(savedPort);
if (PtInRect(lpt, &okBox)) {
validate: if (ValidTapeID(theDialog)) {
*itemHit = ok;
HiliteControl(okHdl, 1);
Delay(8L, &t);
HiliteControl(okHdl, 0);
return(true);
} else
theEvent->what = nullEvent;
} else if (PtInRect(lpt, &variableBox)) {
t = GetCtlValue(variableHdl) ? 0 : 1;
SetCtlValue(variableHdl, t);
theEvent->what = nullEvent;
} else if (PtInRect(lpt, &modeBox)) {
t = GetCtlValue(modeHdl) ? 0 : 1;
SetCtlValue(modeHdl, t);
theEvent->what = nullEvent;
}
break;
}
return(false);
}
/*
* CreatorTypeFilter - manage user events during the Creator/Type dialog
*
*/
pascal Boolean
CreatorTypeFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
long t;
Point lpt;
GrafPtr savedPort;
switch (theEvent->what) {
case keyDown:
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
goto done;
break;
default:
break;
}
break;
case mouseDown:
lpt = theEvent->where;
GetPort(&savedPort);
SetPort((GrafPtr) theDialog);
GlobalToLocal(&lpt);
SetPort(savedPort);
if (PtInRect(lpt, &okBox)) {
done:
*itemHit = ok;
HiliteControl(okHdl, 1);
Delay(8L, &t);
HiliteControl(okHdl, 0);
return(true);
}
break;
}
return(false);
}
/*
* FloppyFilter - manage user events during the Floppy dialog
*
*/
int drive;
pascal Boolean
FloppyFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
#pragma unused(theDialog)
EventRecord e;
if (theEvent->what == keyDown) {
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
*itemHit = cancel;
return(true);
default:
break;
}
}
if (GetOSEvent(diskMask, &e)) {
drive = e.message & 0xffff;
*itemHit = ok;
return(true);
}
return(false);
}
/*
* DoBlockSize - put the block size dialog on the screen
*
* Puts the current block size into the edit field.
*/
void
DoBlockSize(void)
{
short itemHit;
DialogPtr theDialog;
Handle hdl;
short type;
Rect box;
char text[256];
PenState pn;
GrafPtr thePort;
GetPort(&thePort);
theDialog = GetNewDialog(blockID, nil, (WindowPtr) -1);
GetDItem(theDialog, sizeItem, &type, &hdl, &box);
NumToString((long) pref.blocking, text);
SetIText(hdl, text);
SelIText(theDialog, sizeItem, 0, 32767);
GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
SetPort(theDialog);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(BlockFilter, &itemHit);
} while ((itemHit != ok) && (itemHit != cancel));
DisposDialog(theDialog);
SetPort(thePort);
}
/*
* DoTapeOptions - put the tape unit number dialog on the screen
*
* Puts the tape unit number into the edit field.
*/
void
DoTapeOptions(void)
{
short itemHit;
DialogPtr theDialog;
Handle hdl;
short type;
Rect box;
char text[256];
PenState pn;
GrafPtr thePort;
long n;
GetPort(&thePort);
theDialog = GetNewDialog(tapeID, nil, (WindowPtr) -1);
GetDItem(theDialog, scsiIDItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.unit, text);
SetIText(hdl, text);
GetDItem(theDialog, minTOItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.minTO, text);
SetIText(hdl, text);
GetDItem(theDialog, motionTOItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.motionTO, text);
SetIText(hdl, text);
GetDItem(theDialog, rewindTOItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.rewindTO, text);
SetIText(hdl, text);
GetDItem(theDialog, densityItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.densityCode, text);
SetIText(hdl, text);
GetDItem(theDialog, speedItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.speed, text);
SetIText(hdl, text);
GetDItem(theDialog, bufModeItem, &type, &hdl, &box);
NumToString((long) pref.tapeVars.bufMode, text);
SetIText(hdl, text);
GetDItem(theDialog, variableItem, &type, (Handle *) &variableHdl, &variableBox);
SetCtlValue(variableHdl, (pref.tapeVars.forceVariable) ? 1 : 0);
GetDItem(theDialog, modeSelectItem, &type, (Handle *) &modeHdl, &modeBox);
SetCtlValue(modeHdl, (pref.tapeVars.forceModeSelect) ? 1 : 0);
SelIText(theDialog, scsiIDItem, 0, 32767);
GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
SetPort(theDialog);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(TapeFilter, &itemHit);
} while ((itemHit != ok) && (itemHit != cancel));
if (itemHit == ok) {
GetDItem(theDialog, minTOItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.minTO = n;
GetDItem(theDialog, motionTOItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.motionTO = n;
GetDItem(theDialog, rewindTOItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.rewindTO = n;
GetDItem(theDialog, densityItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.densityCode = n;
GetDItem(theDialog, speedItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.speed = n;
GetDItem(theDialog, bufModeItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
pref.tapeVars.bufMode = n;
pref.tapeVars.forceVariable = GetCtlValue(variableHdl) ? true : false;
pref.tapeVars.forceModeSelect = GetCtlValue(modeHdl) ? true : false;
}
DisposDialog(theDialog);
SetPort(thePort);
}
/*
* DoCreatorType - put the set Creator/Type dialog on the screen
*
* Puts the current Creator and Type into the edit field.
*/
void
DoCreatorType(void)
{
short itemHit;
DialogPtr theDialog;
Handle hdl;
short type;
int n;
Rect box;
char text[256];
PenState pn;
GrafPtr thePort;
GetPort(&thePort);
theDialog = GetNewDialog(typeID, nil, (WindowPtr) -1);
GetDItem(theDialog, creatorItem, &type, &hdl, &box);
text[0] = 4;
strncpy(&text[1], pref.creator, 4);
SetIText(hdl, text);
GetDItem(theDialog, typeItem, &type, &hdl, &box);
text[0] = 4;
strncpy(&text[1], pref.type, 4);
SetIText(hdl, text);
SelIText(theDialog, creatorItem, 0, 32767);
GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
SetPort(theDialog);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(CreatorTypeFilter, &itemHit);
} while ((itemHit != ok) && (itemHit != cancel) && (itemHit != saveItem));
if (itemHit == ok) {
GetDItem(theDialog, creatorItem, &type, &hdl, &box);
GetIText(hdl, text);
n = (unsigned char) text[0];
if (n > 4)
n = 4;
memset(pref.creator, ' ', 4);
memcpy(pref.creator, &text[1], n);
GetDItem(theDialog, typeItem, &type, &hdl, &box);
GetIText(hdl, text);
n = (unsigned char) text[0];
if (n > 4)
n = 4;
memset(pref.type, ' ', 4);
memcpy(pref.type, &text[1], n);
}
DisposDialog(theDialog);
SetPort(thePort);
}
/*
* DoInsertFloppy - put the floppy dialog on the screen
*/
int
DoInsertFloppy(void)
{
short itemHit;
DialogPtr theDialog;
drive = 0;
theDialog = GetNewDialog(floppyID, nil, (WindowPtr) -1);
do {
ModalDialog(FloppyFilter, &itemHit);
if (itemHit == ejectItem) {
DiskEject(1);
DiskEject(2);
}
} while ((itemHit != ok) && (itemHit != cancel));
DisposDialog(theDialog);
return(drive);
}
/*
* OSAlert - put a generic OS Error Alert on the screen
*
* Used for errors not handled in another way (yet).
*/
OSAlert(char *p0, char *p1, char *p2, OSErr err)
{
char buf[256];
/*
* Manage the contingency of being called for resources missing!
*/
if (GetResource('ALRT', osErrID) == nil) {
GrafPtr wmPort;
long t;
Rect r;
GetWMgrPort(&wmPort);
SetPort(wmPort);
SetRect(&r, 140, 150, 360, 180);
EraseRect(&r);
MoveTo(150,170);
DrawString("\pPANIC! Resources Missing!");
Delay(600L, &t);
ExitToShell();
}
NumToString((long) err, buf);
ParamText(p0, p1, p2, buf);
StopAlert(osErrID, nil);
}
/*
* PgmAlert - put a program logic alert on the screen
*/
int
PgmAlert(char *p0, char *p1, char *p2)
{
ParamText(p0, p1, p2, nil);
return(StopAlert(pgmErrID, nil));
}
/*
* HFSAlert - put a "HFS only" alert on the screen
*/
void
HFSAlert(void)
{
StopAlert(hfsID, nil);
}
/*
* VersionAlert - put a "6.0.5 or later" alert on the screen
*/
void
VersionAlert(void)
{
StopAlert(versionID, nil);
}
/*
* DFAlert - Oops, disk is full
*/
void
DFAlert(void)
{
StopAlert(dfID, nil);
}
/*
* ArSkipAlert - put a "skipping archive file" note on the screen
*/
void
ArSkipAlert(void)
{
NoteAlert(askipID, nil);
}
/*
* StkErrAlert - put a stack corrupted alert on the screen
*/
void
StkErrAlert(void)
{
StopAlert(stkErrID, nil);
ExitToShell();
}
/*
* StopGoAlert - put an alert on the screen
*/
Boolean
StopGoAlert(const char *p0)
{
ParamText(p0, nil, nil, nil);
if (StopAlert(stopGoID, nil) == ok)
return(false);
return(true);
}
/*
* PgmAlert - put a program logic alert on the screen
*/
void
GenericAlert(const char *p0)
{
ParamText(p0, nil, nil, nil);
StopAlert(genericID, nil);
}